//
//  AppDelegate.m
//  project
//
//  Created by Macmini on 2017/10/16.
//  Copyright © 2017年 Macmini. All rights reserved.
//

#import "AppDelegate.h"

#import "zhangyalin.h"
#import "CLTabBarViewController.h"
#import "LoginNavigationController.h"
#import "LoginViewController.h"
#import "CLNavigationViewController.h"
#import <MJExtension.h>
#import "KGUserDataSource.h"
#import "JJLuckMoneyMessage.h"
#import "JJRecalMessage.h"
#import "KGConversationListVC.h"
ZWUserModel *loginuserInfo = nil;

BOOL is_Ic = NO;
NSString *token = @"";
BOOL is_nickname = NO;

NSString *phone = @"";
NSString *password = @"";

@interface AppDelegate ()
@property (nonatomic,strong)KGUserDataSource *dataSource;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self createDefaultDocumentIfNeed];
    [PXYNotic addObserver:self selector:@selector(isLoginKind) name:@"loginKind" object:nil]; //登录种类(用户或中介)
         [self setRootViewController];
    [self getUserInfo];
    
   
    [self setRootViewController];
    [[RCIM sharedRCIM] initWithAppKey:@"0vnjpoad0cpbz"];
    
    // 获取头像信息
    _dataSource = [[KGUserDataSource alloc] init];
    [[RCIM sharedRCIM] setUserInfoDataSource:_dataSource];
    
    // 注册红包消息
    [[RCIM sharedRCIM] registerMessageType:[JJLuckMoneyMessage class]];
    
    [[RCIM sharedRCIM] registerMessageType:[JJRecalMessage class]];
    
    
    // john   9GMnw9RDHP7qQ/0SNrl/PCb5NDtUcwko6Dg8ItLlzZF9p/sxAmbqAoGY6kRFRMHQv+rZ3OA2ic8ODro5juzvMw==
    
    // jack   zTqG4tuECwwNZNzQAg6vDSb5NDtUcwko6Dg8ItLlzZF9p/sxAmbqAj1FeCQ1LsDp1gOFHHIWkA/xCWT+QLCgKQ==
    
    
   
    
    return YES;
}
#pragma mark - Private Methods
- (void)createDefaultDocumentIfNeed
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error = nil;
    if (![fileManager isExecutableFileAtPath:PATH_CHATREC_IMAGE]) {
        [fileManager createDirectoryAtPath:PATH_CHATREC_IMAGE withIntermediateDirectories:YES attributes:nil error:&error];
        if (error) {
            //            TLLogError([self class], @"createDefaultDocumentIfNeed", error);
        }
    }   if (![fileManager isExecutableFileAtPath:PATH_CHATREC_RECORD]) {
        [fileManager createDirectoryAtPath:PATH_CHATREC_RECORD withIntermediateDirectories:YES attributes:nil error:&error];
        if (error) {
            //            TLLogError([self class], @"createDefaultDocumentIfNeed", error);
        }
    }
    
    if (![fileManager isExecutableFileAtPath:PATH_USERINFO]) {
        [fileManager createDirectoryAtPath:PATH_USERINFO withIntermediateDirectories:YES attributes:nil error:&error];
        if (error) {
            //            TLLogError([self class], @"createDefaultDocumentIfNeed", error);
        }
    }
}


-(void)setRootViewController
{
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
 //   self.window.rootViewController = [[CLTabBarViewController alloc] init];
    LoginViewController *loginVC = [LoginViewController new];
    LoginNavigationController *loginNVC = [[LoginNavigationController alloc] initWithRootViewController:loginVC];
    self.window.rootViewController = loginNVC;
    [self.window makeKeyAndVisible];
}

- (void)getUserInfo {
    
    ZWUserModel *data2  = [NSKeyedUnarchiver unarchiveObjectWithFile:PATH_USERINFO_DATA];
    loginuserInfo = data2;
    if (loginuserInfo) {
        token = loginuserInfo.token;
    }
}

- (void)isLoginKind {
    
    
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
